package com.ming.study.rabbitma.producter.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
public class ProductController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/send")
    public void sendMessage(){
        String messageId = UUID.randomUUID().toString();
        String messageData = "Test Message:Hello World!!!";
        String current = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        Map<String,Object> map = new HashMap<>();
        map.put("messageId",messageId);
        map.put("data",messageData);
        map.put("current",current);
        rabbitTemplate.convertAndSend("TestExchange","123",map,new CorrelationData(UUID.randomUUID().toString()));
    }
}
